const pool = require('../utils/utils.js')

module.exports = async function (ctx, next) {
//   console.log(ctx.request)
  const { userid} = ctx.request.body;
  if (userid){
    let sqlStr = "DELETE FROM user WHERE userid="+userid
    console.log(sqlStr);
    let res = await new Promise((resolve, reject) => {
      pool.query(sqlStr, (err, result) => {
        if (err) {
          reject(err)
        } else {
          resolve(result)
        }
      })
    })
    ctx.body = {
      code: 200,
      msg: '删除成功'
    }
  }else{
    ctx.body = {
      code: 400,
      msg: '删除失败'
    }
  }
  await next()
}